import 'package:web_socket_channel/io.dart';

void main() {
  var secure = true;
  var HOST_NAME = '127.0.0.1';
  var port = 44444;
  var url = '${secure ? "wss" : "ws"}://$HOST_NAME:$port';
  var message = 'hello, world';
  try {
    print('开始新连接... ${url}');
    var channel = IOWebSocketChannel.connect(url);
    channel.stream.listen((message) {
      print('$message');
      channel.sink.close(10086);
    }, onDone: () {
      print('done');
    }, onError: (error) {
      print('$error');
    });
    channel.sink.add(message);
  } catch (e) {
    print('$e');
  }
}
